    //构造函数对象
    function Jquery(arg) {
        //定义一个空的数组来接收匹配到的元素
        this.elements = [];
        switch (typeof arg) {
            case 'function':
                //如果是函数，应该加载window.onload事件
                regEvent(window, 'load', arg);
                console.log('%c【注册了onload事件】', 'background:yellow;')
                break;
            case 'string':
                //如果是字符串，那么就是选择器
                if (arg.charAt(0) == '.') {
                    //如果是类选择器，为了更好的兼容，我们不使用js内置的获取类的函数，因为兼容性不好，我们自己写一个
                    this.elements = getClass(document, arg.substr(1));
                } else if (arg.charAt(0) == '#') {
                    //如果是id选择器
                    this.elements.push(document.getElementById(arg.substr(1)));
                } else {
                    //标签选择器
                    this.elements = document.getElementsByTagName(arg);
                }
                console.log('%c【通过$()获取到的元素】', 'background:yellow');
                console.log(this.elements);
                break;
            case 'object':
                this.elements.push(arg);
                console.log('%c【通过eq()选择器获取到的元素】', 'background:yellow');
                console.log(this.elements);
                break;
        }

    }

    //创建构造函数$返回
    function $(arg) {
        return new Jquery(arg);
    }

    //封装一个注册事件的兼容函数
    function regEvent(obj, type, fn) {
        if (obj.addEventListener) {
            //能力检测
            return obj.addEventListener(type, fn, false);
        } else {
            return obj.attachEvent('on' + type, fn);
        }
    }
    //封装一个获取类的兼容函数
    function getClass(oclass, cn) {
        //创建一个空数组用来接收所有符合要求的类
        var arr = [];
        //查找出页面所有的标签
        var allTag = oclass.getElementsByTagName('*');
        //定义正则边界
        var reg = new RegExp(cn, i);
        //匹配所有有类名的元素
        for (var i = 0, length = allTag.length; i < length; i++) {
            if (reg.test(allTag[i].className)) {
                arr.push(allTag[i]);
            }
        }
        return arr;
    }
    //封装一个获取样式的兼容函数
    function getStyle(obj, attr) {
        if (obj.currentStyle) {
            return obj.currentStyle[attr];
        } else {
            return window.getComputedStyle(obj, null)[attr];
        }
    }
    //定义一个函数合并两个数组
    function mergerTwoArr(arr1, arr2) {
        for (var i = 0, length = arr2.length; i < length; i++) {
            arr1.push(arr2[i]);
        }
    }
    //原型拓展
    Jquery.prototype.eq = function(n) {
            // console.log('%c【通过eq()选择器获取了第' + n + '个%s】', 'background:yellow;', this.elements[n]);
            return $(this.elements[n]);
        }
        //find查找
    Jquery.prototype.find = function(str) {
            var tmpData = [];
            for (i = 0, length = this.elements.length; i < length; i++) {
                switch (str.charAt(0)) {
                    case '.':
                        var cdr = getClass(this.elements[i], str.substr(1));
                        break;
                    default:
                        var cdr = this.elements[i].getElementsByTagName(str);
                        break;
                }
                mergerTwoArr(tmpData, cdr);
            }
            console.log('%c【通过find()函数找到的元素】', 'background:yellow')
            console.log(tmpData);
            this.elements = tmpData;
            return this;
        }
        //on方法注册事件
    Jquery.prototype.on = function(type, fn) {
            for (var i = 0, length = this.elements.length; i < length; i++) {

                console.log('%c【给%s注册了' + type + '事件】', 'background:yellow', this.elements[i]);
                regEvent(this.elements[i], type, fn);
            }
            return this;
        }
        //设置css属性
    Jquery.prototype.css = function() {
            //支持的参数
            //如果是一个参数，那么是获取单个样式
            //如果是两个参数，那么是设置单个样式
            //如果是一个对象，那么是设置多个样式

            switch (arguments.length) {
                case 1:
                    switch (typeof arguments[0]) {
                        case 'string': //获取属性
                            for (var i = 0, length = this.elements.length; i < length; i++) {

                                console.log('%c【获取到%s样式】', 'background:yellow', this.elements[i]);
                                console.log('%c' + arguments[0] + ':' + getStyle(this.elements[i], arguments[0]), 'background:#000;color:#fff');
                                return getStyle(this.elements[i], arguments[0]);
                            }
                            break;
                        case 'object':
                            for (var i = 0, length = this.elements.length; i < length; i++) {

                                console.log('%c 【给%s使用json格式设置了如下样式：', 'background:yellow', this.elements[i]);
                                for (k in arguments[0]) {
                                    console.log('%c' + k + ':' + arguments[0][k], 'background:#000; color:#fff');
                                }
                                for (k in arguments[0]) {
                                    this.elements[i].style[k] = arguments[0][k];
                                }
                            }
                            return this;
                            break;
                    }
                    break;
                case 2:
                    for (var i = 0, length = this.elements.length; i < length; i++) {
                        console.log('【设置单个样式（参数方法）】' + arguments[0] + ':' + arguments[1]);
                        this.elements[i].style[arguments[0]] = arguments[1];
                    }
                    return this;
                    break;
            }
        }
        //设置读取属性
    Jquery.prototype.attr = function() {
            switch (arguments.length) {
                case 1:
                    switch (typeof arguments[0]) {
                        case 'object':
                            //对象类型参数，赋值
                            for (var i = 0, length = this.elements.length; i < length; i++) {
                                console.log('%c【给%s使用json格式设置了如下属性】', 'background:yellow', this.elements[i]);
                                for (k in arguments[0]) {
                                    this.elements[i].setAttribute(k, arguments[0][k]);
                                    console.log('%c' + k + ':' + arguments[0][k], 'background:#000;color:#fff');
                                }
                            }
                            return this;
                            break;
                        case 'string':
                            //字符串类型参数，取值
                            for (var i = 0, length = this.elements.length; i < length; i++) {
                                console.log('%c【获取到%s的属性】', 'background:yellow', this.elements[i]);
                                console.log('%c' + arguments[0] + ':' + this.elements[i].getAttribute(arguments[0]), 'background:#000;color:#fff');
                                return this.elements[i].getAttribute(arguments[0], this.elements[i].getAttribute(arguments[0]));
                            }
                            break;
                    }
                case 2:
                    for (var i = 0, length = this.elements.length; i < length; i++) {
                        console.log('%c【给%s设置了如下属性】', 'background:yellow', this.elements[i]);
                        this.elements[i].setAttribute(arguments[0], arguments[1]);
                        console.log('%c' + arguments[0] + ':' + arguments[1], 'background:#000;color:#fff');
                    }
                    return this;
                    break;
            }

        }
        //获取索引
    Jquery.prototype.index = function(obj) {
        for (var i = 0, length = this.elements.length; i < length; i++) {
            var parents = this.elements[i].parentNode.children;
            for (var j = 0, length = parents.length; j < length; j++) {
                if (this.elements[i] == parents[j]) {
                    console.log('%c【获取到%s的索引,索引值是' + j + '】', 'background:yellow;', this.elements[i]);
                    return j;
                }
            }
        }
    }